Skip to content

fix: keep set operations after subquery operands at the outer query - #914

Merged
kvlonge merged 3 commits into
mainfrom
fix/union-after-scalar-subquery
Oct 2, 2026
Merged

kvlonge merged 3 commits into
mainfrom
fix/union-after-scalar-subquery

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Why

A set operation after a parenthesised subquery in an expression (WHERE a.x < (SELECT …) UNION ALL SELECT …, and the same in HAVING, JOIN ON or BETWEEN) was parsed as part of the subquery. That caused a false B216 column-count error and mis-indented UNION ALL in sqb format (CHI-473). Separately, SQL tests whose fixtures are long UNION ALL chains were analysed in quadratic time (CHI-475).

Changes

Verification

  • Polyglot: regression and scaling tests; old vs new byte-identical on 330+ query × dialect cases apart from the intended fixes; independent review (98 statements in 9 dialects, 414 analysis runs).
  • SQLBuild: focused E2E/unit tests, the new performance guard, make test, make check-ci.

The SQL parser attached a UNION, EXCEPT or INTERSECT that followed a
parenthesized subquery operand, such as `WHERE x < (SELECT ...)`, to the
subquery instead of the outer SELECT. Compile then raised a false B216
column-count error, and the formatter indented the set operation under
the predicate.

Bump polyglot-sql to the parser fix and cover compile, build, Rules and
format through the CLI on DuckDB, plus formatter layout across dialects.
Bump polyglot-sql to linear set-operation scope building. SQL tests whose
fixtures are long UNION ALL chains previously grew quadratically in compile
analysis; 400-row fixtures now analyze in a fraction of the time.

Add a performance guard comparing native analysis time for 50- and 200-row
UNION ALL fixtures across several SQL tests.
@kvlonge
kvlonge enabled auto-merge (squash) October 2, 2026 22:55
@kvlonge
kvlonge merged commit d8d9507 into main Oct 2, 2026
62 of 65 checks passed
@kvlonge
kvlonge deleted the fix/union-after-scalar-subquery branch October 2, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant